package cn.zero.controller;

import cn.zero.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderController {

    @Autowired
    private RestTemplate restTemplate; //用来发请求，代替以前的工具类

    @GetMapping("/getUserById/{id}")
    public User getUserById(@PathVariable Long id){
        //这里的getForObject方法  是用来发get请求的
        //两个参数 一个是请求的url   一个是返回的类型
        //String url = "http://localhost:1020/getUserById/" + id;
        String url = "http://user-server/getUserById/" + id;
        return restTemplate.getForObject(url,User.class);
    }
}
